package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.adoption.AdoptionAddDTO;
import com.rc.pojo.dto.adoption.AdoptionListDTO;
import com.rc.pojo.dto.adoption.AdoptionPageQuery;
import com.rc.pojo.dto.adoption.AdoptionUpdateDTO;
import com.rc.pojo.vo.adoption.AdoptionDetailVO;
import com.rc.pojo.vo.adoption.AdoptionListVO;
import com.rc.pojo.vo.adoption.AdoptionPageVO;
import com.rc.pojo.vo.adoption.AdoptionVO;
import com.rc.web.service.AdoptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/adoption")
@Api(tags = "认养")
@RequiredArgsConstructor
@Validated
public class AdoptionController {
    private final AdoptionService adoptionService;

    @PostMapping
    @ApiOperation("新增")
    public void add(@Validated @RequestBody AdoptionAddDTO dto){
        adoptionService.add(dto);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteOneById(@PathVariable @NotNull Long id){
        adoptionService.deleteOneById(id);
    }


    @PutMapping
    @ApiOperation("删除")
    public void updateOneById(@Validated @RequestBody AdoptionUpdateDTO dto){
        adoptionService.updateById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("详情")
    public AdoptionVO getOneById(@PathVariable Long id){
        return adoptionService.getOneById(id);
    }

    @GetMapping("/page")
    @ApiOperation("分页")
    public Page<AdoptionPageVO> getPage(AdoptionPageQuery query){
        return adoptionService.getPage(query);
    }

    @GetMapping("/list")
    @ApiOperation("客户搜索")
    @WithoutTenant
    public List<AdoptionListVO> getList(AdoptionListDTO dto){
        return adoptionService.getList(dto);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("客户查看详情")
    @WithoutTenant
    public AdoptionDetailVO getDetail(@PathVariable Long id){
        return adoptionService.getDetail(id);
    }
}
